package com.yugao.fintech.draper.websocket.support.impl.resolver;

import com.yugao.fintech.draper.websocket.support.MethodArgumentResolver;
import com.yugao.fintech.draper.websocket.support.NettySession;
import com.yugao.fintech.draper.websocket.support.WebSocketEndpointEventServer;
import io.netty.channel.Channel;
import org.springframework.core.MethodParameter;

public class SessionMethodArgumentResolver implements MethodArgumentResolver {

	@Override
	public boolean support(MethodParameter parameter) {
		return NettySession.class.isAssignableFrom(parameter.getParameterType());
	}

	@Override
	public Object resolveArgument(MethodParameter parameter, Channel channel, Object object) throws Exception {
		return channel.attr(WebSocketEndpointEventServer.SESSION_KEY).get();
	}

}
